/*******************************************************
> Copyright (C) 2024 ==IOT== All rights reserved.
> File Name: stl_list.cpp
> Author: IOT
> Website:www.slq.org
> Created Time: 2024年10月29日 星期二 16时34分45秒
***************************************************/

#include <iostream>
#include <list>

using namespace std;

struct Student {
	string name;
	int age;
	float score;
	Student(string n, int a, float s) : name(n), age(a), score(s)
	{}
	void show()
	{
		cout << "call show" << endl;
		cout << "name:" << name << ", age:" << age << ", score:" << score << endl;
	}
	void show() const
	{
		cout << "call const show" << endl;
		cout << "name:" << name << ", age:" << age << ", score:" << score << endl;
	}
};

int main(int argc,const char* argv[])
{
	Student stu("tom", 21, 67.8);
	
	list<Student> stus;
	stus.push_back(stu);
	
	//cout << stus.front().show() << endl;
	
	stus.push_front(Student("lucy", 21, 70.5));
	stus.front().show();
	stus.back().show();
	
	stus.push_front(Student("张三", 22, 75.5));
	stus.push_front(Student("李四", 23, 85.5));
	
	cout << stus.size() << endl;
	
	//stus.pop_front();
	//cout << stus.size() << endl;
	
	list<Student>::iterator it; // 定义形式，iterator属于list中的类
	
	#if 0
	class iterator {
		Student *ptr;
		
		operator++();
		operator->();
		operator*();
	}
	#endif
	
	for (it = stus.begin(); it != stus.end(); ++it) { // 充当指针角色，用于访问容器元素
		it->show();
		//(*it).show();
		//(it[0]).show(); // error
	}
	
	cout << " ==== " << endl;
	#if 1
	list<Student>::reverse_iterator rit;
	for (rit = stus.rbegin(); rit != stus.rend(); ++rit) { // 充当指针角色，用于访问容器元素
		rit->show();
		//(*it).show();
		//(it[0]).show(); // error
	}
	#endif
	
	auto cit = stus.cbegin();
	for (;cit != stus.cend(); ++cit) {
		cit->show();
	}
    return 0;
}
